package cn.imnaer.service.rpc.location;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.bson.BSONObject;
import org.bson.BasicBSONObject;
import org.bson.types.BasicBSONList;

import cn.imnaer.database.MatchConst;
import cn.imnaer.service.persistence.model.City;
import cn.imnaer.service.persistence.model.consts.CITY;
import cn.imnaer.service.persistence.model.consts.SCENIC;
import cn.imnaer.service.rest.view.model.Place;
import cn.imnaer.service.rpc.common.AbstractRepository;

public class CityRepository   extends  AbstractRepository<City>{
	private CityDaoImpl cityDaoImpl = CityDaoImpl.getInstance().getInstance();

	public CityRepository() {

	}

	public String getCityNameByCityCode(String cityCode) {

		City city = this.cityDaoImpl.findOneByAttribute("cityCode", cityCode);

		if (city != null) {

			return city.getCityName();
		}
		return    null;
	}

	@Override
	public City save(City result) {
		return null;
	}

	

	@Override
	public List<City> search(String keyword) {
				if (keyword != null && !keyword.isEmpty()) {
					BSONObject matcherOne = new BasicBSONObject();
					BasicBSONList arr = new BasicBSONList();
					BSONObject parmasOne = new BasicBSONObject();
					matcherOne.put(MatchConst._REGEX, keyword);
					matcherOne.put(MatchConst._OPTIONS, "i");
					parmasOne.put("pinyin",matcherOne);
					arr.add(parmasOne);
					BSONObject parmasTwo = new BasicBSONObject();
					parmasTwo.put(CITY.cityName, keyword);
					arr.add(parmasTwo);
					BSONObject query = new BasicBSONObject();
					query.put(MatchConst._OR, arr);
					List<City> record = this.cityDaoImpl.findAll(query, null);
	
                     return  record;
				
				}
			
		return  null;
	}

	@Override
	public City findOneByPk(String pkValue, Class<?> clazz) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public City findOneByPk(String pkValue) {
		// TODO Auto-generated method stub
		return null;
	}
}